import 'dart:convert';
import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:wanxiang_app/bean/category_entity.dart';
import 'package:wanxiang_app/bean/extend_entity.dart';
import 'package:wanxiang_app/bean/price_entity.dart';
import 'package:wanxiang_app/bean/query_entity.dart';
import 'package:wanxiang_app/pages/home/detail.dart';
import 'package:wanxiang_app/widgets/account_textField2.dart';

import '../../bean/search_game_list_entity.dart';
import '../../utils/constant.dart';
import '../../utils/network_manager.dart';
import '../../utils/network_url.dart';
import '../../utils/toast_util.dart';
import '../../utils/user_util.dart';
import '../../widgets/account_textField3.dart';
import '../../widgets/filter_dialog.dart';
import '../../widgets/mySearchAppbar.dart';
import '../../widgets/myappbar.dart';
import 'package:get/get.dart';

import '../../widgets/numSection.dart';
import '../../widgets/simple_dialog.dart';
import '../../widgets/tabs.dart';

class SearchResultController extends GetxController {
  @override
  void onInit() {
    super.onInit();
    Map map = Get.arguments;

    // showFilter = map['showFilter'];
    // showSearch = map['showSearch'];
    keyword = map['keyword'];
    tempKeyword = map['keyword'];
    name = map['name'];
    channel_name = map['channel_name'];
    channel_id = map['channel_id'];

    priceData.bprice = '';
    priceData.eprice = '';

    print('onInitonInitonInit~~~~~~~~~~~~');

    // initReal();
    // _getCategory();
    // _getPriceListData();
    // _getExtend();

    _getData();
  }

  @override
  void onClose() {
    super.onClose();
    // dispose();

  }

  initReal() {
    Map aa = {'name': '全部', 'value': ''};
    Map aa1 = {'name': '可二次实名', 'value': '1'};
    Map aa2 = {'name': '可包人脸', 'value': '2'};
    realList.add(aa);
    realList.add(aa1);
    realList.add(aa2);
  }

  bool clickSearch = false;
  bool showFilter = true;
  bool showSearch = true;
  String keyword = '';
  String tempKeyword = '';
  String name = '';
  String channel_name = '';
  String channel_id = '';
  String category_id = '';
  String time_order = '0';
  String price_order = '0';
  String server_id = '';
  String is_msg = '';
  int totalCount = 0;
  int page = 1;
  int totalPage = 1;
  bool showArea = false;
  String pageCountText = '';

  List<SearchGameListData> list = [];
  List<CategoryData> categoryList = [];
  List<CategoryData> secondCategoryList = [];
  List<PriceData> priceList = [];
  List realList = [];

  List<ExtendData> extendList = [];
  late CategoryData secondClickCategory;
  bool showPop = false;

  String area_name = '全部';
  late CategoryData clickCategory;
  late CategoryData clickCategorySecond;
  bool needSecCategory = false;
  void _changeArea(item) {
    clickCategory = item;
    area_name = clickCategory.title;
    category_id = clickCategory.id.toString();
    channel_id = clickCategory.channelId.toString();
    _getGameListData();
    if (clickCategory.title == '全部') {
      secondCategoryList = [];
    } else {
      if(needSecCategory){
        _getSecondCategory();
      }

    }
    update();
  }

   PriceData priceData = PriceData();

  void _getPriceListData() {
    DioManager.getInstance().post(ServiceUrl.priceList, {
      "channel_name": channel_name,
    }, (data) async {
      PriceEntity bannerEntity = PriceEntity.fromJson(jsonDecode(data));
      if (bannerEntity.code != 200) {
        ToastUtil.show(bannerEntity.msg);
      } else {
        priceList = bannerEntity.data;
        PriceData all = PriceData();
        all.content = '全部';
        all.id = '-1';
        all.sortId = '-1';
        all.bprice = '';
        all.eprice = '';
        priceList.insert(0, all);
        priceData = priceList[0];
      }
      update();
    }, (error) {
      ToastUtil.show(error);
    });
  }

  changePage(){
    if(page > totalPage){
      page = totalPage;
    }
    _getGameListData();
  }

  void _getGameListData() {
    // "is_self" 是否官方自营，1--是，0--不是
    Map map = {
      "page":page.toString(),
      "keyword": keyword,
      "bno":'',
      "channel_name": channel_name,
      "category_id": category_id,
      "server_id": server_id,
      "bprice": priceData.bprice,
      "eprice": priceData.eprice,
      "channel_id": channel_id,
      "is_msg": is_msg,
     "pagesize": "20",
       "time_order": time_order,
      "price_order": price_order,
    };
    for(var item in extendList){
      List<String> values = [];
      for(var item2 in item.datas){
        if(item2['selected']){
          values.add(item2['name']);
        }
      }
      if(values.isNotEmpty){
        String aa =values.join('|');
        map.putIfAbsent(item.name, () => aa);
      }

    }

    DioManager.getInstance().post(ServiceUrl.queryBuyGoodsList, map, (data) async {
      SearchGameListEntity bannerEntity = SearchGameListEntity.fromJson(jsonDecode(data));
      list=[];
      if (bannerEntity.code != 200) {
        list.clear();
        totalCount = 0;
        totalPage = 1;
        pageCountText = '$page/${totalPage}';
        ToastUtil.show(bannerEntity.msg);
      } else {
        list = bannerEntity.data;
        if(list.isEmpty){
          totalCount = 0;
          totalPage = 1;
        }else{
          totalCount = list[0].totalcount;
          totalPage = (totalCount/20).ceil() ;
        }
        pageCountText = '$page/${totalPage}';
      }
      print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
      update();
    }, (error) {
      ToastUtil.show(error);
    });
  }

  void _getCategory() {
    DioManager.getInstance().post(ServiceUrl.queryCategoty, {
      "channel_name": channel_name,
      "details_id": '0',
    }, (data) async {
      CategoryEntity bannerEntity = CategoryEntity.fromJson(jsonDecode(data));
      if (bannerEntity.code != 200) {
        ToastUtil.show(bannerEntity.msg);
      } else {
        categoryList = bannerEntity.data;
        CategoryData all = CategoryData();
        all.title = '全部';
        all.id = 0;
        all.parentId = -1;
        if(channel_id.isEmpty){
          all.channelId = 0;
        }else{
          all.channelId = int.parse(channel_id);
        }
        categoryList.insert(0, all);
        _changeArea(categoryList[0]);
        // _getSecondCategory('0');
      }

      update();
    }, (error) {
      ToastUtil.show(error);
    });
  }

  void _getSecondCategory() {
    if (clickCategory.title == '全部') {
      secondCategoryList = [];
      update();
      return;
    }
    DioManager.getInstance().post(ServiceUrl.queryCategoty, {
      "channel_name": channel_name,
      "details_id": clickCategory.parentId == 0
          ? clickCategory.id.toString()
          : clickCategory.parentId.toString(),
    }, (data) async {
      CategoryEntity bannerEntity = CategoryEntity.fromJson(jsonDecode(data));
      if (bannerEntity.code != 200) {
        ToastUtil.show(bannerEntity.msg);
      } else {
        secondCategoryList = bannerEntity.data;
        CategoryData all = CategoryData();
        all.title = '全部';
        all.id = 0;
        all.parentId=0;
        all.channelId = -1;
        secondCategoryList.insert(0, all);
        secondClickCategory = secondCategoryList[0];
      }
      update();
    }, (error) {
      ToastUtil.show(error);
    });
  }

  _getData(){
    DioManager.getInstance().post(ServiceUrl.queryGoodsList, {
      "channel_name": channel_name,
      "keyword":keyword
    }, (data) async {
      SearchGameListEntity bannerEntity = SearchGameListEntity.fromJson(jsonDecode(data));
      if (bannerEntity.code != 200) {
      } else {
      list = bannerEntity.data;

      }
      update();
    }, (error) {
      ToastUtil.show(error);
    });
  }

  void _getExtend() {
    DioManager.getInstance().post(ServiceUrl.extendList, {
      "channel_name": channel_name,
    }, (data) async {
      ExtendEntity bannerEntity = ExtendEntity.fromJson(jsonDecode(data));
      if (bannerEntity.code != 200) {
      } else {
        extendList = bannerEntity.data;
        for (var element in extendList) {
          element.itemOption = element.itemOption.replaceAll("\r\n", ",");
          List<String> bb = element.itemOption.split(',');

          List<Map> aa = [];
          for (var element2 in bb) {
            List<String> bb = element2.split('|');
            Map map = {'name': bb[0], 'selected': false};
            aa.add(map);
          }
          element.datas = aa;
        }
      }
      update();
    }, (error) {
      ToastUtil.show(error);
    });
  }

  reset() {
    _changeArea(categoryList[0]);
    is_msg = realList[0]['value'];
    priceData = priceList[0];
    for (var item in extendList) {
      for (var item2 in item.datas) {
        item2['selected'] = false;
      }
    }
  }
}

class SearchResultPage extends GetView<SearchResultController> {
  late SearchResultController controller;
  late BuildContext context;

  @override
  Widget build(BuildContext context1) {
    Get.lazyPut<SearchResultController>(() => SearchResultController());
    controller = Get.find();
    context = context1;
    return GetBuilder<SearchResultController>(
      builder: (_) {
        return Scaffold(
            appBar: controller.clickSearch?
            MySearchAppBar(
              key: ValueKey('result'),
                context: context,
                defaultText: controller.tempKeyword,
                callBack: (str) {
                    if(str=='back'){
                      controller.clickSearch  = false;
                      controller.update();
                    }else if(str=='goSearch'){
                      controller.keyword = controller.tempKeyword ;
                      controller.page = 1;
                      controller._getGameListData();
                      FocusScope.of(context).unfocus();
                    }else{
                      controller.tempKeyword = str;
                    }
                }
            ):

            // MyAppBar(
            //     context: context,
            //     title: controller.name,
            //     hasLeading: true,
            //     showFilter: controller.showFilter,
            //     showSearch: controller.showSearch,
            //     callBack: (str) {
            //       if (str == 'filter') {
            //         controller.needSecCategory = true;
            //         controller.showPop = true;
            //         controller.update();
            //       }else if(str == 'search'){
            //         controller.clickSearch = true;
            //         controller.update();
            //       }
            //     })

            MyAppBar(
            context: context,
            title: controller.name,
            hasLeading: true,
            callBack: (str) {
              if (str == 'filter') {
                controller.needSecCategory = true;
                controller.showPop = true;
                controller.update();
              }else if(str == 'search'){
                controller.clickSearch = true;
                controller.update();
              }
            })

            ,
            backgroundColor: Colors.white,
            body: SingleChildScrollView(
              child:  Container(
                child: Stack(
                  children: [
                    Column(
                      children: [
                        // _sort(),
                        controller.showArea ? _buildArea() : Container(),
                        SizedBox(height: 10.h,),
                        controller.list.isEmpty?_empty():Column(
                          children: [
                            Column(
                              children: _all(),
                            ),
                            // _bottom()
                          ],
                        )
                      ],
                    ),
                    controller.showPop ? _content() : Container()
                  ],
                ),
              ),
            ));
      },
    );
  }
  
  Widget _empty(){
    return Container(
      margin: EdgeInsets.only(top: 80.h),
      alignment: Alignment.center,
      child: Image.asset(Constant.IMG_BASE+'empty.png',width: 150.w,height: 127.h,),
    );
  }

  Widget _buildArea() {
    return Container(
        padding: EdgeInsets.only(left: 16.w, right: 16.w),
        width: MediaQuery.of(context).size.width,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            SizedBox(
              height: 10.h,
            ),
            Wrap(
                spacing: 15,
                children: controller.categoryList
                    .map((item) => _itemArea(item))
                    .toList()),
          ],
        ));
  }

  Widget _itemArea(item) {
    return InkWell(
        onTap: () {
          controller._changeArea(item);
        },
        child: RawChip(
          label: Text(
            item.title,
            style: TextStyle(
                color: item.id == controller.clickCategory.id
                    ? const Color(0xFFf43f50)
                    : const Color(0xFF333333),
                fontSize: 13.sp),
          ),
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(6.r)),
          backgroundColor: item.id == controller.clickCategory.id
              ? const Color(0xFFfceff0)
              : const Color(0xFFF5F5F5),
          padding: const EdgeInsets.symmetric(vertical: 10),
        ));
  }

  Widget _itemArea2(CategoryData item) {
    return InkWell(
        onTap: () {
          if (item.id == 0) {
            controller.server_id = item.parentId.toString();
          } else {
            controller.server_id = item.id.toString();
          }
          controller.secondClickCategory = item;
          controller.update();
        },
        child: RawChip(
          label: Text(
            item.title,
            style: TextStyle(
                color: item.id == controller.secondClickCategory.id
                    ? const Color(0xFFf43f50)
                    : const Color(0xFF333333),
                fontSize: 13.sp),
          ),
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(6.r)),
          backgroundColor: item.id == controller.secondClickCategory.id
              ? const Color(0xFFfceff0)
              : const Color(0xFFF5F5F5),
          padding: const EdgeInsets.symmetric(vertical: 10),
        ));
  }

  Widget _itemReal(Map item) {
    return InkWell(
        onTap: () {
          controller.is_msg = item['value'];
          controller.update();
        },
        child: RawChip(
          label: Text(
            item['name'],
            style: TextStyle(
                color: item['value'] == controller.is_msg
                    ? const Color(0xFFf43f50)
                    : const Color(0xFF333333),
                fontSize: 13.sp),
          ),
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(6.r)),
          backgroundColor: item['value'] == controller.is_msg
              ? const Color(0xFFfceff0)
              : const Color(0xFFF5F5F5),
          padding: const EdgeInsets.symmetric(vertical: 10),
        ));
  }

  Widget _itemExtend(Map item,ExtendData elment,list) {
    return InkWell(
        onTap: () {
          if( elment.controlType=='multi-radio'){
            for(var item2 in list){
              item2['selected'] = false;
            }
            item['selected'] = true;
          }else{
            item['selected'] = !item['selected'];
          }

          controller.update();
        },
        child: RawChip(
          label: Text(
            item['name'],
            style: TextStyle(
                color: item['selected']
                    ? const Color(0xFFf43f50)
                    : const Color(0xFF333333),
                fontSize: 13.sp),
          ),
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(6.r)),
          backgroundColor: item['selected']
              ? const Color(0xFFfceff0)
              : const Color(0xFFF5F5F5),
          padding: const EdgeInsets.symmetric(vertical: 10),
        ));
  }

  Widget _sort() {
    return Container(
      padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 10.w),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          InkWell(
              onTap: () {
                controller.showArea = !controller.showArea;
                controller.update();
              },
              child: Row(
                children: [
                  Text(controller.area_name),
                  const Icon(
                    Icons.arrow_drop_down,
                    size: 24.0,
                    semanticLabel: 'Text to announce in accessibility modes',
                  ),
                ],
              )),
          InkWell(
              onTap: () {
                controller.time_order = '0';
                if (controller.price_order == '0') {
                  controller.price_order = '1';
                } else if (controller.price_order == '1') {
                  controller.price_order = '2';
                } else if (controller.price_order == '2') {
                  controller.price_order = '0';
                }
                controller._getGameListData();
              },
              child: Row(
                children: [
                  const Text('价格排序'),
                  controller.price_order == '0'
                      ? const Icon(
                          Icons.unfold_more,
                          size: 24.0,
                        )
                      : (controller.price_order == '1'
                          ? const Icon(
                              Icons.arrow_drop_down,
                              color: Colors.blue,
                              size: 24.0,
                            )
                          : const Icon(
                              Icons.arrow_drop_up,
                              color: Colors.blue,
                              size: 24.0,
                            )),
                ],
              )),
          InkWell(
              onTap: () {
                controller.price_order = '0';
                if (controller.time_order == '0') {
                  controller.time_order = '1';
                } else if (controller.time_order == '1') {
                  controller.time_order = '2';
                } else if (controller.time_order == '2') {
                  controller.time_order = '0';
                }
                controller._getGameListData();
              },
              child: Row(
                children: [
                  const Text('时间排序'),
                  controller.time_order == '0'
                      ? const Icon(
                          Icons.unfold_more,
                          size: 24.0,
                        )
                      : (controller.time_order == '1'
                          ? const Icon(
                              Icons.arrow_drop_down,
                              color: Colors.blue,
                              size: 24.0,
                            )
                          : const Icon(
                              Icons.arrow_drop_up,
                              color: Colors.blue,
                              size: 24.0,
                            )),
                ],
              ))
        ],
      ),
    );
  }

  List<Widget> _all() {
    List<Widget> aa = [];
    for (int i = 0; i < controller.list.length; i++) {
      aa.add(_gameItems(controller.list[i], i));
    }
    return aa;
  }
  TextEditingController _ediController = TextEditingController();
  Widget _bottom(){

    return Container(
      padding: EdgeInsets.fromLTRB(10.w, 20.h, 10.w, 30.h),
      width: MediaQuery.of(context).size.width,
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              controller.page==1?
              _btnDisable('首页'):_btnNormal('首页'),
              controller.page==1?
              _btnDisable('上一页'):_btnNormal('上一页'),
              _btnDisable(controller.pageCountText),
              controller.page==controller.totalPage?
              _btnDisable('下一页'):_btnNormal('下一页'),
              controller.page==controller.totalPage?
              _btnDisable('尾页'):_btnNormal('尾页'),
            ],
          ),
          SizedBox(height: 15.h,),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const Text('输入页数'),
              SizedBox(width: 5.w,),
              Container(
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(5.r),
                  border: Border.all(color: const Color(0xFFEDEEEF),width: 1.w),
                ),
                width: 100.w,
                height: 30.h,
                child: AccountEdit3Text(
                    key: const ValueKey('page'),
                    keyboardType: TextInputType.number,
                    defaultText: controller.page.toString(),
                    textAlign:TextAlign.center,
                    contentStrCallBack: (String content) {
                  controller.page = int.parse(content);
                },controllerCallBack:(TextEditingController _controller2){
                  _ediController = _controller2;
                }


                ),
              ),
              SizedBox(width: 5.w,),
              const Text('页'),
              SizedBox(width: 5.w,),
              InkWell(
                onTap: (){
                  controller._getGameListData();
                },
                child: const Text('跳转'),
              )


            ],
          )
        ],
      ),
    );
  }

  Widget _btnDisable(text){
    return InkWell(
      onTap: (){

      },
      child: Container(
        alignment: Alignment.center,
        width: 60.w,
        height: 30.h,
        decoration: BoxDecoration(
          color: const Color(0xfff1f1f1),
          borderRadius: BorderRadius.circular(5.r),
          border: Border.all(color: const Color(0xFFEDEEEF),width: 1.w),
        ),
        child: Text(text,style: const TextStyle(
          color: Color(0xffc0c4cc)
        ),),
      )
    ) ;
  }

  Widget _btnNormal(text){
    return InkWell(
        onTap: (){
          if(text == '首页'){
            controller.page = 1;
            controller.changePage();
          }else  if(text == '上一页'){
            controller.page --;
            controller.changePage();
          }else  if(text == '下一页'){
            controller.page ++;
            controller.changePage();
          }else  if(text == '尾页'){
            controller.page =controller.totalPage;
            controller.changePage();
          }
          _ediController.text = controller.page.toString();
        },
        child: Container(
          alignment: Alignment.center,
          width: 60.w,
          height: 30.h,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(5.r),
            border: Border.all(color: const Color(0xFFEDEEEF),width: 1.w),
          ),
          child: Text(text,style: const TextStyle(
          ),),
        )
    ) ;
  }

  void _pop() {
    showDialog(
        context: context,
        builder: (context1) {
          return StatefulBuilder(
            builder: (context2, state) {
              return Dialog(
                insetPadding: EdgeInsets.only(
                    top: MediaQueryData.fromWindow(window).padding.top + 56),
                shape: const RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(0))),
                child: FilterDialog(
                  key: const ValueKey('filter'),
                  callBack: (String content) {},
                ),
              );
            },
          );
        });
  }


  Widget _officer(SearchGameListData item) {
    print('item.isDeductible44=='+item.isDeductible);
    if(item.isDeductible=='1'){
      return InkWell(
        onTap: (){
          showDialog(context: context, builder: (BuildContext context1) {
            return MySimpleDialog(callBack: (String content) {
              if(content == 'cancel'){
                Navigator.pop(context1);
              }else if(content == 'sure'){
                Navigator.pop(context1);
              }
            },
              msg: item.baopei,
              sureText: "确定",
            );
          });
        },
        child: Container(
          child: Image.asset(Constant.IMG_BASE+'qianyue.png',width: 52.w,height: 17.h,fit: BoxFit.fitWidth,),
        )
      );
    }

    return item.isSelf==0? InkWell(
      onTap: (){
        showDialog(context: context, builder: (BuildContext context1) {
          return MySimpleDialog(callBack: (String content) {
            if(content == 'cancel'){
              Navigator.pop(context1);
            }else if(content == 'sure'){
              Navigator.pop(context1);
            }
          },
            msg: item.baopei,
            sureText: "确定",
          );
        });
      },
      child: Container(
        child: Image.asset(Constant.IMG_BASE+'baopei.png',width: 52.w,height: 17.h,fit: BoxFit.fitWidth,),
      )
    ) :Container();
  }

  Widget _gameItems(SearchGameListData item, index) {
    return InkWell(
        onTap: () {
          // UserUtil.saveRecord('');
          Get.to(()=>DetailPage(),arguments: {
            "goods_id":item.id.toString(),
            "record_id":controller.channel_id,
            "channel_name":controller.channel_name,
            "title":controller.name,
          },preventDuplicates:false)?.then((value) => controller._getGameListData());
        },
        child: Container(
          margin: EdgeInsets.only(left: 16.w, right: 13.w, ),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                  width: 140.w,
                  height: 120.h,
                  child: Stack(
                    children: [
                      ClipRRect(
                        borderRadius: BorderRadius.circular(10.r),
                        child: Image.network(
                          item.imgUrl,
                          fit: BoxFit.cover,
                          width: 140.w,
                          height: 120.w,
                        ),
                      ),
                      _officer(item),
                    ],
                  )),
              SizedBox(
                width: 10.w,
              ),
              Container(
                  width: MediaQuery.of(context).size.width -
                      29.w -
                      14.w -
                      100.w -
                      40.w,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        '${item.title}',
                        style: TextStyle(
                            color: Color(0xFF333333),
                            fontSize: 14.sp,
                            fontWeight: FontWeight.bold),
                        maxLines: 3,
                        textAlign: TextAlign.left,
                        overflow: TextOverflow.ellipsis,
                      ),
                      SizedBox(
                        height: 10.h,
                      ),
                      Text(
                        '区服:${item.categoryText}',
                        style: TextStyle(
                            color: Color(0xFF666666), fontSize: 13.sp),
                      ),
                      SizedBox(
                        height: 6.h,
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              _second(item),
                              _fenqi(item),
                            ],
                          ),

                          Row(
                            children: [
                              Text(
                                '¥',
                                style: TextStyle(
                                    color: Color(0xFFFF0000), fontSize: 12.sp),
                              ),
                              Text(
                                '${item.sellPrice}',
                                style: TextStyle(
                                    color: Color(0xFFFF0000), fontSize: 15.sp),
                              ),
                            ],
                          )
                     
                        ],
                      )
                    ],
                  ))
            ],
          ),
        ));
  }

  Widget _second(SearchGameListData item){
    String aa = '';
    if(item.isMsg == '2'){
      aa ='包人脸';
    }
    else if(item.isMsg == '1'){
      aa ='可二次';
    }else{
      aa ='不包人脸';
    }
    print('isMsgisMsgisMsg==='+item.isMsg);
    return Container(
      padding: EdgeInsets.only(left: 5.w,right: 5.w,top: 3.h,bottom: 3.h),
      decoration: BoxDecoration(
          border: Border.all(
            color: Color(0xFF007BE5), //边框颜色
            width: 1.w, //宽度
          ),
        borderRadius: BorderRadius.circular(5.r)
      ),
      child: Text(aa,style: TextStyle(
        color: Color(0xFF007BE5),
        fontSize: 8.sp
      ),),
    );
  }

  Widget _fenqi(SearchGameListData item){
    String aa = '不可分期';
    if(item.isBystages == '1'){
      aa ='可分期';
    }

    print('isBystagesisBystages==='+item.isBystages);

    return Container(
      margin: EdgeInsets.only(left: 3.w),
      padding: EdgeInsets.only(left: 5.w,right: 5.w,top: 3.h,bottom: 3.h),
      decoration: BoxDecoration(
          border: Border.all(
            color: Color(0xFF007BE5), //边框颜色
            width: 1.w, //宽度
          ),
          borderRadius: BorderRadius.circular(5.r)
      ),
      child: Text(aa,style: TextStyle(
          color: Color(0xFF007BE5),
          fontSize: 8.sp
      ),),
    );
  }

  Widget _filterItem(title, list) {
    return Container(
      width: MediaQuery.of(context).size.width,
      padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 16.h),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            title,
            style: TextStyle(fontSize: 16.sp),
          ),
          SizedBox(
            height: 5.h,
          ),
          Wrap(
              spacing: 15,
              children: controller.categoryList
                  .map((item) => _itemArea(item))
                  .toList()),
        ],
      ),
    );
  }

  Widget _filterPrice(title, list) {
    return Container(
        padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 16.h),
        width: MediaQuery.of(context).size.width,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              title,
              style: TextStyle(fontSize: 16.sp),
            ),
            SizedBox(
              height: 5.h,
            ),
            Wrap(
                spacing: 15,
                children: controller.priceList
                    .map((item) => _itemPrice(item))
                    .toList()),
          ],
        ));
  }

  Widget _filterSecondService(title, list) {
    return Container(
          padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 16.h),
          width: MediaQuery.of(context).size.width,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                title,
                style: TextStyle(fontSize: 16.sp),
              ),
              SizedBox(
                height: 5.h,
              ),
              Wrap(
                  spacing: 15,
                  children: controller.secondCategoryList
                      .map((item) => _itemArea2(item))
                      .toList()),
            ],
          )
    ) ;
  }



  Widget _filterReal(title, list) {
    return Container(
        padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 16.h),
        width: MediaQuery.of(context).size.width,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              title,
              style: TextStyle(fontSize: 16.sp),
            ),
            SizedBox(
              height: 5.h,
            ),
            Wrap(
                spacing: 15,
                children: controller.realList
                    .map((item) => _itemReal(item))
                    .toList()),
          ],
        ));
  }

  List<Widget> _filterExtends() {
    List<Widget> aa = [];
    for (var element in controller.extendList) {
      aa.add(_filterExtend(element.title, element.datas,element));
    }
    return aa;
  }

  Widget _filterExtend(title, List<Map> list,elment) {
    return Container(
        padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 16.h),
        width: MediaQuery.of(context).size.width,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              title,
              style: TextStyle(fontSize: 16.sp),
            ),
            SizedBox(
              height: 5.h,
            ),
            Wrap(
                spacing: 15,
                children: list.map((item) => _itemExtend(item,elment,list)).toList()),
          ],
        ));
  }

  Widget _itemPrice(item) {
    return InkWell(
        onTap: () {
          controller.priceData = item;
          controller.update();
        },
        child: RawChip(
          label: Text(
            item.content,
            style: TextStyle(
                color: item.id == controller.priceData.id
                    ? const Color(0xFFf43f50)
                    : const Color(0xFF333333),
                fontSize: 13.sp),
          ),
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(6.r)),
          backgroundColor: item.id == controller.priceData.id
              ? const Color(0xFFfceff0)
              : const Color(0xFFF5F5F5),
          padding: const EdgeInsets.symmetric(vertical: 10),
        ));
  }

  Widget _content() {
    return Container(
      height: MediaQuery.of(context).size.height,
      width: MediaQuery.of(context).size.width,
      color: Colors.white,
      child: Stack(
        children: [
          Container(
              height: MediaQuery.of(context).size.height - 56.h,
              color: Colors.white,
              child: SingleChildScrollView(
                  child: Column(
                children: [
                  Column(
                    children: [
                       InkWell(
                        onTap:(){
                          controller.needSecCategory = false;
                          controller.showPop = false;
                          controller.update();
                         },
                        child: Container(
                          margin: EdgeInsets.only(top: 5.h),
                          child:  Row(
                            mainAxisAlignment: MainAxisAlignment.end,
                            children: [
                              Icon(Icons.highlight_off),
                              Text('关闭'),
                              SizedBox(width: 10.w,),
                            ],
                          )
                        )
                      )
                    ,

                      _filterItem('游戏区服：', ''),
                      controller.secondCategoryList.isNotEmpty
                          ? _filterSecondService(
                              '${controller.clickCategory.title}服务器：',
                              controller.secondCategoryList)
                          : Container(),
                      _filterReal('实名包脸：', controller.realList),
                      _filterPrice('价格区间：', controller.priceList),
                      Column(children: _filterExtends())
                    ],
                  ),
                  SizedBox(
                    height: 80.h,
                  )
                ],
              ))),
          Positioned(
              width: MediaQuery.of(context).size.width,
              height: 46.h,
              bottom: 65.h,

              child: Container(
                  color:Colors.white,
                  padding: EdgeInsets.fromLTRB(4.w, 0.h, 4.w, 0.h),
                  child: Row(
                    children: [
                      Expanded(
                          flex: 1,
                          child: InkWell(
                              onTap: () {
                                controller.reset();
                              },
                              child: Container(
                                height: 46.h,
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                    color: const Color(0xFFF7F8FC),
                                    borderRadius: BorderRadius.only(
                                        bottomLeft: Radius.circular(14.r))),
                                child: const Text(
                                  '重置',
                                  style: TextStyle(color: Color(0xFF333333)),
                                ),
                              ))),
                      Expanded(
                          flex: 1,
                          child: InkWell(
                              onTap: () {
                                controller.showPop = false;
                                controller._getGameListData();
                              },
                              child: Container(
                                height: 46.h,
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                    color: const Color(0xFFF43F50),
                                    borderRadius: BorderRadius.only(
                                        bottomRight: Radius.circular(14.r))),
                                child: const Text(
                                  '确定',
                                  style: TextStyle(color: Colors.white),
                                ),
                              ))),
                    ],
                  )))
        ],
      ),
    );
  }
}
